﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net;
using Tulde.Windows.Music.ViewModel;

namespace Tulde.Windows.App
{
    /// <summary>
    /// Interaction logic for Credentials.xaml
    /// </summary>
    public partial class Credentials : Window
    {
        public ICredentials SelectedCredentials
        {
            get;
            private set;
        }
        public Credentials()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(Credentials_Closing);
        }

        void Credentials_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (String.IsNullOrEmpty(this.username.Text) ||
               String.IsNullOrEmpty(this.password.Text) ||
               String.IsNullOrEmpty(this.token.Text))
            {
                e.Cancel = true;
            }
        }

        private void searchButton_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(this.username.Text) ||
                String.IsNullOrEmpty(this.password.Text) ||
                String.IsNullOrEmpty(this.token.Text))
            {
                MessageBox.Show("Please enter your information.");
            }
            else
            {
                var x = new Mp3TunesCredentials();
                x.UserName = this.username.Text;
                x.Password = this.password.Text;
                x.Token = this.token.Text;
                this.DialogResult = true;
                this.SelectedCredentials = x;
                this.Close();
            }
            
        }
    }
}
